package com.jc;

<<<<<<< HEAD
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.jc.utils.Strings;
import com.mjoys.util.DateUtil;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.test.annotation.IfProfileValue;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author wangli
 * @create 2016-12-23 18:36
 * @description
 */
public class Test {
    private final static String START_TIME = "startTime";
    private final static String END_TIME = "endTime";

    public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {


        Person person= new Person().setName("wang").setAge(18).setTest(11);
        Student student = new Student();
        org.springframework.beans.BeanUtils.copyProperties(person, student);
        System.out.println(student.toString());

//        Person person = new Person();
//
//        person.setStartTime(2017010111);
//        person.setEndTime(2017010322);
////        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(person);
//
//        System.out.println("之内" + starttimeAndEndtimeHandle(person, 2L));
//        System.out.println(person.getStartTime());
//        System.out.println(person.getEndTime());

//        BeanUtils.setProperty(person, START_TIME, 129879);
//        beanWrapper.setPropertyValue(END_TIME, 8190827);
//        System.out.println(person.getStartTime());
//        System.out.println(person.getEndTime());


//        System.out.println("#广告主id \n" + getUserPrivilegeAdvSql(295L) +";");
//        System.out.println("#计划id \n" +getUserPrivilegePlanSql(195L) + ";");
//        System.out.println("#小组id\n" + getUserPrivilegeTeamSql(1688L) + ";");
//        Person test = getTest(new Person());
//
//        System.out.println("是否允许被删除: " + isAllowBeDelete(new Person().setName("")));
//
//        Person person = new Person().setName("wang");
//        StringBuffer sql = new StringBuffer();
//        sql.append("test");
//        appendSqlByNonNull(sql, "and name =",person.getName());
//        appendSqlByNonNull(sql, "and age = ", person);
//        System.out.println(sql.toString());

//        String test = "[\"abc\",\"cde\",\"efg\",\"hij\"]";
//        List<String> strings = Splitter.on(",").omitEmptyStrings().splitToList(test.replace("[", "").replace("]", "").replace("\"",""));
//        t.win WIN,
//        case t.flow  when 0 then  0  else t.bid / t.flow end BIDRATE,
//        case t.win  when 0 then  0  else t.click / t.win end CLICKRATE,
//        t.spend SPEND,
//        case t.bid  when 0 then  0  else t.bidprice / t.bid end AVGBID,
//        case t.win  when 0 then  0  else t.spend / t.win * 1000 end AVGFEET,
//        case t.click  when 0 then  0  else t.spend / t.click end AVGFEE,
//        t.bid BID,
//        case t.bid  when 0 then  0  else t.win / t.bid end WINP,
//        t.flow FLOW,
//        t.download DOWNLOAD,
//        ifnull(t.REACH, 0) REACH,
//                ifnull(t.QUIT, 0) QUIT,
//                ifnull(case t.click  when 0 then  0  else t.reach / t.click end, 0) REACHRATE,
//                ifnull(case t.reach when 0 then 0  else t.duration/t.reach end, 0) DURATION,
//                ifnull(t.BINARYHOT, 0) BINARYHOT,
//                ifnull(case t.reach  when 0 then  0  else t.binaryhot / t.reach end, 0) HOTRATE,
//                ifnull(cart, 0) CART,
//                ifnull(orders, 0) ORDERS,
//        String sqlPart = "case t.bid  when 0 then  0  else t.win / t.bid end WINP,";
//        List<String> list = Splitter.on(" ").omitEmptyStrings().splitToList(sqlPart.replace(",", ""));
//
//        System.out.print("list::   " + list.get(list.size() - 1 ));
//        HashSet<String> sets = Sets.newHashSet("reachrate", "win");
//
//        System.out.println(sets.contains(list.get(list.size() - 1 ).toLowerCase()));

    }


    public static <T> Boolean starttimeAndEndtimeHandle(T t, Long days) {

        Boolean isInDayRange = Boolean.FALSE;
        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(t);
        //为起始时间添加字符串00, 为终止时间添加23
        Integer startTime = (Integer) beanWrapper.getPropertyValue(START_TIME);
        Integer endTime = (Integer) beanWrapper.getPropertyValue(END_TIME);
        if (startTime.toString().length() == 8) {
            beanWrapper.setPropertyValue(START_TIME, Integer.valueOf(startTime + "00"));
        }
        if (endTime.toString().length() == 8) {
            beanWrapper.setPropertyValue(END_TIME, Integer.valueOf(endTime + "23"));
        }
        long startTimeDay = DateUtil.parseStrDate(startTime.toString().substring(0, 8), "yyyyMMdd").getTime();
        long endTimeDay = DateUtil.parseStrDate(endTime.toString().substring(0, 8), "yyyyMMdd").getTime();
        if (days != null && DateUtil.dateDiff("d", startTimeDay, endTimeDay) <= days) {
            isInDayRange = Boolean.TRUE;
        }
        return isInDayRange;
    }

    public static <T> T getTest(T t) {
        System.out.println(t.getClass().toString());
        ArrayList<String> strings = Lists.newArrayList(Splitter.on(".").omitEmptyStrings().split(t.getClass().toString()));
        System.out.println(strings.get(strings.size() - 1));

        return t;
    }

    public static StringBuffer getUserPrivilegeAdvSql(Long advid) {
        StringBuffer sql = new StringBuffer();
        sql.append(" select id from ads.t_userinfo where 1 = (select distinct(case when advid = 0 then 1 else 0 end) from UAC.T_USER_PLAN a where userid = " + advid + ") ");
        sql.append(" union ");
        sql.append(" select id from ads.t_userinfo where id in (select advid from UAC.T_USER_PLAN a where userid = " + advid + " and advid != 0) ");
        return sql;
    }

    public static StringBuffer getUserPrivilegePlanSql(Long planid) {
        StringBuffer sql = new StringBuffer();
        sql.append(" select id from ads.t_adplan where 1 = (select distinct(case when advid = 0 then 1 else 0 end) from UAC.T_USER_PLAN a where userid = " + planid + ") ");
        sql.append(" union ");
        sql.append(" select id from ads.t_adplan where userid in (select advid from UAC.T_USER_PLAN a where userid = " + planid + " and pid = 0) ");
        sql.append(" union ");
        sql.append(" select id from ads.t_adplan where id in (select pid from UAC.T_USER_PLAN a where userid = " + planid + " and pid != 0) ");
        return sql;
    }

    public static StringBuffer getUserPrivilegeTeamSql(Long teamid) {
        StringBuffer sql = new StringBuffer();
        sql.append(" select id from ads.t_adteam where 1 = (select distinct(case when advid = 0 then 1 else 0 end) from UAC.T_USER_PLAN a where userid = " + teamid + ") ");
        sql.append(" union ");
        sql.append(" select id from ads.t_adteam where userid in (select advid from UAC.T_USER_PLAN a where userid = " + teamid + " and pid = 0) ");
        sql.append(" union ");
        sql.append(" select id from ads.t_adteam where pid in (select pid from UAC.T_USER_PLAN a where userid = " + teamid + " and pid != 0) ");
        return sql;
    }

    public static StringBuffer appendSqlByNonNull(StringBuffer sql, String snippets, Object object) {
        if (object != null) {
            sql.append(" ").append(snippets).append(" ").append(object).append("  ");
        }
        return sql;
    }

    public static <T> Boolean isAllowBeDelete(T object) throws IllegalAccessException {
        Boolean isAllowBeDelete = Boolean.FALSE;
        for (Field f : object.getClass().getDeclaredFields()) {
            f.setAccessible(true);
            if (f.get(object) != null) { //判断字段是否为空，并且对象属性中的基本都会转为对象类型来判断
                isAllowBeDelete = Boolean.TRUE;
            }
        }
        return isAllowBeDelete;
    }
=======
import com.google.common.base.CharMatcher;
import com.google.common.collect.ComparisonChain;

import java.util.Date;
import java.util.logging.SocketHandler;

/**
 * @author wangli
 * @create 2017-01-08 10:24
 * @description
 */
public class Test implements Comparable<Test> {

  public static void main(String[] args) {

    //        Date date = new Date();
//    String aaa = "lakaksjdfh12a214";
//    //        char[] test = CharMatcher.DIGIT.retainFrom("lakaksjdfh12a214").toCharArray();
//    char[] test = CharMatcher.DIGIT.trimAndCollapseFrom(aaa);
//    for (int i = 0; i < test.length; i++) {
//      System.out.println("数字数组" + test[i]);
//    }
//    System.out.println("数字 " + test);
  }

  private String name;

  private Integer age;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int compareTo(Test that) {
    return ComparisonChain.start()
        .compare(this.name, that.name)
        .compare(this.age, that.age)
        .result();
  }

  public Integer getAge() {
    return age;
  }

  public Test setAge(Integer age) {
    this.age = age;
    return this;
  }

  //    @Override
  //    public boolean equals(Object o) {
  //        if (this == o) return true;
  //        if (o == null || getClass() != o.getClass()) return false;
  //
  //        Test test = (Test) o;
  //
  //        if (!name.equals(test.name)) return false;
  //        return age.equals(test.age);
  //
  //    }

  @Override
  public String toString() {
    return "Test{" + "name='" + name + '\'' + ", age=" + age + '}';
  }
>>>>>>> 6f518bc829fc202bb54ff1788533503deb087277
}
